package _interview150;

import _object.ListNode;

/**
 * 86. 分隔链表
 */
public class No86 {
    public ListNode partition(ListNode head, int x) {
        ListNode l1 = new ListNode(-1), d1 = l1;
        ListNode l2 = new ListNode(-1), d2 = l2;
        while (head != null) {
            if (head.val < x) {
                l1.next = head;
                l1 = l1.next;
            } else {
                l2.next = head;
                l2 = l2.next;
            }
            head = head.next;
        }
        l2.next = null;
        l1.next = d2.next;
        return d1.next;
    }
}
